package com.cplh.sharding.demo.controller;


import com.cplh.sharding.demo.entry.Orders;
import com.cplh.sharding.demo.service.OrdersService;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author: kangzhijin
 * @since: 2022/10/12
 * @version: 1.0
 * @description:
 **/
@Slf4j
@RestController
@RequestMapping("/sharding")
public class ShardingOrderTestController {
    @Resource
    private OrdersService ordersService;

    @GetMapping("/test/insertOrder/{orderId}")
    public String insertOrder(@PathVariable("orderId") String orderId) {
        Orders order = new Orders();
        order.setOrderId(orderId);
        order.setOrderInfo(orderId + "-Info");
        ordersService.save(order);

        return "ok";
    }

    @GetMapping("/test/queryOrder/{orderId}")
    public Object queryOrder(@PathVariable("orderId") String orderId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("orderId", orderId);
        return ordersService.queryOrdersMapperNormal(params);
    }




}
